<script>
function member_submit() {
    //用户名
    if(!isempty('account','用户名不能为空'))return false;
    //密码验证
    if(!isempty('password','密码不能为空'))return false;
    if(!isempty('password2','确认密码不能为空'))return false;
    if($("input[name=password]").val() != $("input[name=password2]").val()){
        alert('两次密码输入不一样');
        return false;
    }
    //真实姓名
    if(!isempty('name','真实姓名不能为空'))return false;
	//邮箱验证
	if(!isempty('email','邮箱不能为空'))return false;
	var email = $("input[name=email]").val();
	var reg = /^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/;
	if (!reg.test(email)) {
        alert('邮箱格式不正确');
        $("input[name=email]").focus();
        return false;
    }
    //职位
    if(!isempty('position','职位不能为空'))return false;
	//角色验证
	if($("#roleId").val() == 0){
		alert('请选择您的角色');
		return false;
	}
	return true;
}

$(function(){
    $("input[name=account]").blur(function(){
        var account = $(this).val();
        if($.trim(account)=='')return;
        $.get("<?=blang_url('home/valid_account')?>",{account:account}, function(status){
           if(status == 0){
               $("#accountTips").text('恭喜您,此帐号还未被注册').css("color","#0a8e61");
           }else{
               $("input[name=account]").val('').focus();
               $("#accountTips").text('帐号 ('+account+') 已被注册').css("color","red");
           }
        });
    });
})
</script>

<!--菜单 start-->
<?php $this->load->view('defaults/common/left');?>
<!--菜单 end-->
<div id="content">
    <div class="page-header">
        <div class="container-fluid">
        <h1><?=lang('menu_yhgl')?></h1>
        <?=$this->breadcrumb->generateHTML();?>
        </div>
    </div>
    <div class="container-fluid">
        <div class="panel panel-default">
            <div class="panel-heading">
                <h3 class="panel-title"><i class="fa fa-pencil"></i><?=lang('menu_xzyh')?></h3>
            </div>
            <div class="panel-body">
                <div class="table-responsive">
                    <div id="contents_container" style="margin-top: 10px;overflow: hidden;">
                      <form class="form-horizontal" action="<?=blang_url('users/member/'.$post_type)?>" method="post" name="memberform" onsubmit="return member_submit()" autocomplete="off" >
                            <div class="form-group">
                                <label class="col-sm-2 control-label">用户名</label>
                                <div class="col-sm-10">
                                    <input class="form-control"  type="text" name="account" value="<?=$userFirst['account']?>" />
                                  <span id="accountTips"></span>
                                </div>
                            </div>
                            <?php if($post_type!='edit'):?>
                            <div class="form-group">
                                <label class="col-sm-2 control-label">密码</label>
                                <div class="col-sm-10">
                                   <input class="form-control"  type="password" name="password"  />
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-2 control-label">确认密码</label>
                                <div class="col-sm-10">
                                   <input class="form-control"  type="password" name="password2" />
                                </div>
                            </div>
                            <?php endif;?> 
                            <div class="form-group">
                                <label class="col-sm-2 control-label">真实姓名</label>
                                <div class="col-sm-10">
                                   <input class="form-control"  type="text" name="name" value="<?=$userFirst['name']?>" />
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-2 control-label">邮箱</label>
                                <div class="col-sm-10">
                                    <input class="form-control"  type="text" name="email" value="<?=$userFirst['email']?>" />
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-2 control-label">职位</label>
                                <div class="col-sm-10">
                                    <input class="form-control" type="text" name="position" value="<?=$userFirst['position']?>" />
                                </div>
                            </div>
                             <div class="form-group">
                                <label class="col-sm-2 control-label">角色</label>
                                <div class="col-sm-10">
                                    <select class="form-control" name="roleNameId" id="roleId">
                                      <option value="" >--请选择--</option>
                                      <?php foreach ($roleList as $row):?>
                                         <option value="<?=$row['id'].'_'.$row['name_en']?>"  ><?=$row['name']?></option>
                                      <?php endforeach;?>
                                   </select>
                                </div>
                            </div>
                            
                            <div class="form-group">
                              <label class="col-sm-2 control-label"></label>
                              <div class="col-sm-10">
                                  <input type="hidden" name="id" value="<?=$userFirst['id']?>" />
                                  <input class="btn btn-primary" style="padding:8px 30px" type="submit" value="添加" name="submits" />
                              </div>
                            </div>
                        </form>
                       </div>
                    
                </div>
            </div>
        </div>
    </div>
 
</div>
